<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- <form action="/login" method="post" id="form1" enctype="multipart/form-data">
        <input type="text" name="username" id="username"/>
        <input type="password" name="pwd" id="pwd"/>
        <input type="file" name="myfile"/>
        <input type="button" id="btn" value="提交" />
    </form> -->
    <input type="text" name="username" id="username"/>
    <input type="password" name="pwd" id="pwd"/>
    <input type="file" name="myfile" id="myfile"/>
    <input type="button" id="btn" value="提交" />
</body>
<script>
    var btn = document.getElementById("btn");
    var form1 = document.getElementById("form1");
    btn.onclick = function() {
        var formData = new FormData();
        formData.append("username", "zhangsan");
        formData.append("showfile", document.getElementById("myfile").files[0]);
        fetch("http://localhost:3000/login", {
            body: formData,
            method: 'post'
        })
    }

    // var btn = document.getElementById("btn");
    // btn.onclick = function() {
    //     var userName = document.getElementById("username");
    //     var pwd = document.getElementById("pwd");
    //     var data = {username: userName.value, pwd: pwd.value};
    //     fetch("http://localhost:3000/login", {
    //         body: JSON.stringify(data),
    //         method: 'post',
    //         headers: new Headers({
    //             'Content-Type': 'application/json'
    //         })
    //     })
    //     .then(res => {
    //         return res.json();
    //     })
    //     .then(res => {
    //         console.log(res)
    //     })
    // }
</script>
</html>